using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.Office.Interop.Excel;

namespace CocaCola_Inventory_System.Forms
{
    public partial class ExportToExcel : Form
    {
        private System.Data.DataTable data;
        private System.Data.DataTable table;
        string file = "";
        bool success;        
        public ExportToExcel()
        {
            InitializeComponent();
        }

        private void _ListFilter1_Load(object sender, EventArgs e)
        {

        }

        private void ExportToExcel_Load(object sender, EventArgs e)
        {
            ListFilter.SourceLabel = "Available Columns";
            ListFilter.DestinationLabel = "Select Columns For Export";
            if (data == null)
            {
                MessageBox.Show("No Data Available To Export");
                this.Close();
            }
            
            ExportTable = data;
            
        }

        public System.Data.DataTable ExportTable
        {
            set
            {
                data = value;
                System.Data.DataTable Columns = new System.Data.DataTable();
                Columns.Columns.Add("ColumnName");
                foreach (DataColumn c in data.Columns)
                    Columns.Rows.Add(c.ColumnName);
                ListFilter.SourceDataTable = Columns;
                ListFilter.ColumnNameDisplay = "Name";                

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            table = data.Copy();
            foreach (DataRow row in ListFilter.SourceDataTable.Rows)
                table.Columns.Remove(row["ColumnName"].ToString());
            if (table.Columns.Count == 0)
            {
                MessageBox.Show("You Must Select At Least One Column");
                return;
            }

            ExportToExcelOrder eo = new ExportToExcelOrder();
            //eo.MdiParent = this.MdiParent;
            eo.ExportTable = table.Copy();
            eo.ShowDialog();
            

        }


        
        

        



/*
        public string SortColumnName
        {
            set
            {
                sort = value;
                ListFilter.SortColumnName = value;
            }
        }

        public string DisplayColumnName
        {
            set
            {
                displaymember = value;
                ListFilter.ColumnNameDisplay = value;
            }
        }
        */
    }
}